package com.yinNuo.collectWool.mobileApi.collectWoolApi;

import com.yinNuo.collectWool.collectWoolHttp.JiuZhangHeadlinesHttps;
import com.yinNuo.collectWool.core.BaseAPI;
import com.yinNuo.collectWool.core.Response;
import com.yinNuo.collectWool.mobileApi.entity.User;
import com.yinNuo.collectWool.mobileApi.service.IndexService;
import com.yinNuo.collectWool.utils.ToolUtil;
import com.yinNuo.collectWool.mobileApi.vo.JiuZhangHeadlinesBaseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yinNuo
 * create at: 2021/12/6 下午3:37
 * @description: 九章头条接口功能模块
 */
@RestController
@RequestMapping("/jjiuZhangHeadlines")
public class JiuZhangHeadlinesApi extends BaseAPI {
    @Autowired
    private IndexService indexService;
    @Autowired
    private User user;
    @Autowired
    private JiuZhangHeadlinesHttps jiuZhangHeadlinesHttps;

    /**
     * 输入手机号获得验证码
     */
    public Response getCode(@RequestBody JiuZhangHeadlinesBaseVo jiuZhangHeadlinesBaseVo) {
        String result = "";
        return Response.ok(jiuZhangHeadlinesHttps.inputPhone(jiuZhangHeadlinesBaseVo.getPhone()));
    }

    /**
     * 根据验证码和手机号登录
     *
     * @param jiuZhangHeadlinesBaseVo
     * @return
     */
    @RequestMapping("/login")
    @ResponseBody
    public Response login(@RequestBody JiuZhangHeadlinesBaseVo jiuZhangHeadlinesBaseVo) {
        String result = "";
        if (ToolUtil.isNotEmpty(jiuZhangHeadlinesBaseVo.getPhone()) && ToolUtil.isNotEmpty(jiuZhangHeadlinesBaseVo.getCode())) {
            result = jiuZhangHeadlinesHttps.login(jiuZhangHeadlinesBaseVo.getPhone(), jiuZhangHeadlinesBaseVo.getCode());
        } else {
            result = "登录失败";
        }
        return Response.ok(result);
    }

    /**
     * 手动添加token
     * @param jiuZhangHeadlinesBaseVo
     * @return
     */
    @RequestMapping("/addToken")
    @ResponseBody
    public Response addToken(@RequestBody JiuZhangHeadlinesBaseVo jiuZhangHeadlinesBaseVo) {
        user.setToken(jiuZhangHeadlinesBaseVo.getToken());
        return Response.ok("添加成功！");
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @RequestMapping("/getUserInfo")
    @ResponseBody
    public Response getUserInfo() {
        return Response.ok(indexService.getPersonMessage());
    }



}
